package edu.gatech.asthma.database;

import android.annotation.SuppressLint;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Value object for profiles that contains all the information
 */
public class ProfileVO {
	
	int identifier;
	String name;
	int gender;
	String birthday;
	int weight;
	int weight_unit;
	int height;
	int height_unit;
	int ethnicity;
	int bg_color;
	int tint_color;
	int accent_color;
	int pic;
	float best;
	
	/**
	 * General initialization
	 */
	public ProfileVO(){
		identifier = -1;
		name = "";
		gender = -1;
		birthday = "";
		weight = -1;
		weight_unit = -1;
		height = -1;
		height_unit = -1;
		ethnicity = -1;
		bg_color = 0;
		tint_color = 0;
		accent_color = 0;
		pic = 0;
		best = 0;
	}

	/**
	 * Initialize with inputs
	 * @param identifier
	 * @param name 
	 * @param gender
	 * @param birthday
	 * @param weight 
	 * @param weightUnit pounds or kilograms
	 * @param height
	 * @param heightUnit centimeters or feet/inches
	 * @param ethnicity 
	 * @param bg_color customized background color
	 * @param tint_color tint color for the pic
	 * @param accent_color accent color for the pic
	 * @param pic customized picture for the profile
	 */
	public ProfileVO(int identifier, String name, int gender, String birthday, int weight, int weight_unit, int height, int height_unit, int ethnicity, int bg_color, int tint_color, int accent_color, int pic) {
		this.identifier = identifier;
		this.name = name;
		this.gender = gender;
		this.birthday = birthday;
		this.weight = weight;
		this.weight_unit = weight_unit;
		this.height = height;
		this.height_unit = height_unit;
		this.ethnicity = ethnicity;
		this.bg_color = bg_color;
		this.tint_color = tint_color;
		this.accent_color = accent_color;
		this.pic = pic;
	}
	
	public float getBest() {
		return best;
	}

	public void setBest(float best) {
		this.best = best;
	}

	public int getIdentifier() {
		return identifier;
	}
	
	public void setIdentifier(int identifier) {
		this.identifier = identifier;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public int getWeight_unit() {
		return weight_unit;
	}

	public void setWeight_unit(int weight_unit) {
		this.weight_unit = weight_unit;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getHeight_unit() {
		return height_unit;
	}

	public void setHeight_unit(int height_unit) {
		this.height_unit = height_unit;
	}

	public int getEthnicity() {
		return ethnicity;
	}

	public void setEthnicity(int ethnicity) {
		this.ethnicity = ethnicity;
	}

	public int getBgColor() {
		return bg_color;
	}

	public void setBgColor(int color) {
		this.bg_color = color;
	}
	
	public int getTintColor() {
		return tint_color;
	}

	public void setTintColor(int color) {
		this.tint_color = color;
	}
	
	public int getAccentColor() {
		return accent_color;
	}

	public void setAccentColor(int color) {
		this.accent_color = color;
	}

	public int getPic() {
		return pic;
	}

	public void setPic(int pic) {
		this.pic = pic;
	}
	
	
	/**
	 * Returns current age (in years) of profile based on current date and birth date
	 * @return age
	 */
	@SuppressLint("SimpleDateFormat")
	public int getAge() {
		String currentDate = new SimpleDateFormat("MM-dd-yyyy").format(new Date());
		String birthDate = getBirthday();
		
		//Arrays that separates the dates by the hyphens [MM, dd, yyyy]
		String[] currentDateArray = currentDate.split("-");
		String[] birthDateArray = birthDate.split("-");
		
		int age = Integer.parseInt(currentDateArray[2]) - Integer.parseInt(birthDateArray[2]);
		
		//if current month is less than birth month, subtract  a year
		if (Integer.parseInt(currentDateArray[0]) < Integer.parseInt(birthDateArray[0]))
			age--;
		//else if current month is equal to birth month but current day is less than birth year, also subtract
		else if (Integer.parseInt(currentDateArray[0]) == Integer.parseInt(birthDateArray[0]))
			if (Integer.parseInt(currentDateArray[1]) < Integer.parseInt(birthDateArray[1]))
				age--;
		return age;
	}
}
